package com.morimoto.rmlib;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class StorageManager {
	
	private Context mContext = null;
	private SharedPreferences mPref = null;
	private SharedPreferences.Editor mEditor = null;  

	public StorageManager(Context context, String key) {
		mContext = context;
	    mPref = mContext.getSharedPreferences(key, Activity.MODE_PRIVATE);
	    mEditor = mPref.edit();
//	    RMLog.print("----SharedPreferences----\n" + mPref.toString() + "\n-----------------------");
//	    RMLog.print("----SharedPreferences.Editor----\n" + mEditor.toString() + "\n-----------------------");
	}
	
	public boolean isContain(String key) {
		return mPref.contains(key) ? true : false;
	}
	
	public int getInt(String key) {
		return mPref.getInt(key, 0);
	}
	
	public void addInt(String key, int value) {
		mEditor.putInt(key, value);
		mEditor.commit();
	}

	public float getFloat(String key) {
		return mPref.getFloat(key, 0.0f);
	}
	
	public void addFloat(String key, float value) {
		mEditor.putFloat(key, value);
		mEditor.commit();
	}

	public String getString(String key) {
		return mPref.getString(key, "");
	}

	public void addString(String key, String value) {
		mEditor.putString(key, value);
		mEditor.commit();
	}

	public boolean getBoolean(String key) {
		return mPref.getBoolean(key, false);
	}
	
	public void addBoolean(String key, boolean value) {
		mEditor.putBoolean(key, value);
		mEditor.commit();
	}

}
